<?php
//require "../common/SqlUtils.php";
require_once '../common/SqlUtils.php';
$username = $_POST['username'];
$psd = $_POST['psd'];
$newUrl = '';
$msg = '';
session_start();
SqlUtils::$conn=new mysqli("127.0.0.1","root","123456","bank");
$sql="select * from bankcard WHERE CardNo='".$username."' and CardPwd='".$psd."'";
$result=count(SqlUtils::select($sql));
if($result>0){
    $keyValue = md5($username.$psd);
    setcookie('userkey',$keyValue,time()+24*3600,'/');
    $newUrl = 'userinfo.php';
    $msg = '登录成功';
    $_SESSION[$keyValue]=[
        'username'=>$username,
        'psd'=>$psd
    ];
}else{
    $msg = '用户名或密码错误';
    $newUrl = '/user/login.php';
}
?>


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<input type="hidden" id="newUrl" value="<?php echo $newUrl;?>">
<input type="hidden" id="msg" value="<?php echo $msg;?>">
</body>
<script>
    onload = function () {
        var newUrl = document.getElementById('newUrl').value;
        var msg = document.getElementById('msg').value;
        alert(msg);
        location.href = newUrl;
    }
</script>

</html>